
import 'package:base_flutter/base_flutter.dart';
import 'package:ls_work/a_yyt/models/floor_list_entity.dart';
import 'package:ls_work/net/api/http_api.dart';
import 'package:ls_work/net/post_request.dart';
import 'package:ls_work/net/response/devices/building_list_data.dart';
import 'package:ls_work/util/request_url_utils.dart';

import '../net/response/building_list_bean.dart';
import '../net/response/floor_list_bean.dart';

class BuildingListModel extends BaseMvvmModel {
  @override
  void onCleared() {}

  ///获取楼栋列表
  Future<List<BuildingListBean>> getBuildingList() async {
    var map = {"branchId": RequestUrlUtils.branchId};
    var data = await HttpGo.instance.postData(HttpApi.selectBuildingList,
        data: map.toJsonMapStr(), options: PostRequest.urlencodedHeader);

    if ("0" == data["code"]) {
      var list = ((data['data']['rows'] as List?)??[])
          .map((e) => BuildingListBean.fromJson(e))
          .toList();
      return list;
    } else {
      throw data['msg'];
    }
  }

  ///获取楼层列表
  Future<List<FloorListBean>> getFloorList(String buildingId) async {
    var map = {"buildingId": buildingId};
    var data = await HttpGo.instance.postData(HttpApi.floorList,
        data: map.toJsonMapStr(), options: PostRequest.urlencodedHeader);
    if ("0" == data["code"]) {
      var list = ((data['data']['rows'] as List?)??[])
          .map((e) => FloorListBean.fromJson(e))
          .toList();
      return list;
    } else {
      throw data['msg'];
    }
  }
}
